<?php
/**
 * Routing debugger template.
 *
 * @param string   $presenter
 * @param array    $params
 * @param string   $router
 * @param array    $routers
 */

/*use Nette\Debug;*/
/*use Nette\Application\Presenter;*/

?>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Routing debugger</title>

	<style>
	body {
		font: 13px/1.5 sans-serif;
		color: #333;
		background: #fff;
	}

	h1 {
		font-size: 170%;
		color: #165ca3;
	}

	h2 {
		font-size: 150%;
		color: black;
	}

	table {
		padding: 0;
		margin: 0;
		border-collapse:collapse;
	}

	table td, table th {
		color: #525b37;
		background: #fff;
		border: 1px solid #d1cdab;
		padding: 6px;
		text-align: left;
	}

	table th {
		color: #165ca3;
		background: #e3e9ba;
		font-size: 90%;
	}

	table .alt td {
		background: #f8f8f0;
	}

	.may, .yes {
		color: green;
	}

	.yes {
		font-weight: bold;
	}

	pre {
		display: inline;
	}

	</style>
</head>

<body>
	<h1>Routing debugger</h1>

	<p><small>Enter an URL into the address bar and see which routes match it.</small></p>

	<?php if (!empty($presenter)): ?>
		<h2>&#x25ba; <?php echo htmlSpecialChars($presenter . ':' . (isset($params[Presenter::ACTION_KEY]) ? $params[Presenter::ACTION_KEY] : Presenter::$defaultAction)) ?></h2>

		<?php if (empty($params)): ?>
			<p>No parameters.</p>

		<?php else: ?>
			<table>
			<thead>
			<tr>
				<th>Parameter</th>
				<th>Value</th>
			</tr>
			</thead>
			<tbody>
			<?php foreach ($params as $key => $value): ?>
			<tr>
				<td><code><?php echo htmlSpecialChars($key) ?></code></td>
				<td><?php if (is_string($value)):?><code><?php echo htmlSpecialChars($value) ?></code><?php else: Debug::dump($value); endif ?></td>
			</tr>
			<?php endforeach ?>
			</tbody>
			</table>
		<?php endif ?>
	<?php endif ?>

	<!-- ~~~~~~~~~~~ -->

	<?php if (empty($router)): ?>
		<h2>&#x25ba; Not matched</h2>

	<?php else: ?>
		<h2>&#x25ba; Matched by <?php echo htmlSpecialChars($router) ?></h2>
	<?php endif ?>

	<!-- ~~~~~~~~~~~ -->

	<?php if (empty($routers)): ?>
		<p>No routes defined.</p>

	<?php else: ?>
		<table>
		<thead>
		<tr>
			<th>Matched?</th>
			<th>Class</th>
			<th>Mask</th>
			<th>Defaults</th>
		</tr>
		</thead>

		<tbody>
		<?php foreach ($routers as $router): ?>
		<tr>
			<td class="<?php echo $router['matched'] ?>"><?php echo $router['matched'] ?></td>
			<td><code><?php echo htmlSpecialChars($router['class']) ?></code></td>
			<td><code><strong><?php echo htmlSpecialChars($router['mask']) ?></strong></code></td>
			<td><code>
			<?php foreach ($router['defaults'] as $key => $value): ?>
				<?php echo htmlSpecialChars($key), " = ", is_string($value) ? htmlSpecialChars($value) : Debug::dump($value, TRUE) ?><br>
			<?php endforeach ?>
			</code></td>
		</tr>
		<?php endforeach ?>
		</tbody>
		</table>
	<?php endif ?>
</body>
</html>